package com.example.prison.mapper;

import com.example.prison.entity.CarManagement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【car_management】的数据库操作Mapper
* @createDate 2024-06-03 11:07:19
* @Entity com.example.prison.entity.CarManagement
*/
@Mapper
public interface CarManagementMapper extends BaseMapper<CarManagement> {

//    @Select("select * from car_management order by car_id desc")
    @Select("<script>select * from car_management " +
            " <where> " +
            " <if test=\"carNumber != null and carNumber != ''\">and car_number like concat('%',#{carNumber},'%') </if> " +
            " <if test=\"carDepart != null and carDepart != ''\">and car_depart like concat('%',#{carDepart},'%') </if> " +
            " <if test=\"carStatus != null and carStatus != ''\">and car_status like concat('%',#{carStatus},'%') </if> " +
            " </where> " +
            "order by car_id desc</script>")
    List<CarManagement> get(@Param("carNumber")String carNumber,
                            @Param("carDepart")String carDepart,@Param("carStatus")String carStatus);

    @Select("select * from car_management where car_depart!='' or car_depart!=null order by car_id desc")
    List<CarManagement> getInsideCar();

    @Select("select * from car_management where car_depart='' or car_depart=null order by car_id desc")
    List<CarManagement> getOutsideCar();

    @Insert("insert into car_management(car_number, car_depart, car_status) values (#{carNumber}, #{carDepart}, #{carStatus})")
    int add(CarManagement car);

    @Delete("<script>delete from car_management where car_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteCar(@Param("ids") Integer[] ids);

//    @Update("update car_management set car_number=#{car.carNumber},car_depart=#{car.carDepart},car_status=#{car.carStatus} where car_id = #{carId}")
    @Update({"<script> UPDATE car_management",
            "<set>",
            "<if test='car.carNumber != null'>car_number = #{car.carNumber},</if>",
            "<if test='car.carDepart != null'>car_depart = #{car.carDepart},</if>",
            "<if test='car.carStatus != null'>car_status = #{car.carStatus},</if>",
            "</set>",
            "where car_id = #{carId} </script>"})
    int updateCar(CarManagement car,Integer carId);

    @Select("select * from car_management where car_id=#{carId}")
    CarManagement getById(@Param("carId") Integer carId);

    @Select("select * from car_management where car_number like concat('%',#{carNumber},'%') order by car_id desc")
    List<CarManagement> getByNumber(@Param("carNumber") String carNumber);
    @Select("select * from car_management where car_number =#{carNumber}")
    CarManagement getOneByNumber(@Param("carNumber") String carNumber);

    @Select("select * from car_management where car_number =#{carNumber} order by car_id desc")
    List<CarManagement> getListOneByNumber(@Param("carNumber") String carNumber);

    @Select("select * from car_management where car_number =#{carNumber} and car_depart =#{depart} order by car_id desc")
    CarManagement getByNumberAndDepart(@Param("carNumber")String carNumber, @Param("depart")String depart);

    @Select("<script>select * from car_management " +
            " <where> car_depart = #{depart} " +
            " <if test=\"carNumber != null and carNumber != ''\">and car_number like concat('%',#{carNumber},'%') </if> " +
            " </where> " +
            "order by car_id desc</script>")
    List<CarManagement> getRetentionCar(@Param("carNumber")String carNumber, @Param("depart")String depart);

}




